package com.web.bridge.service.impl;

import java.util.List;

import org.hibernate.service.spi.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.web.bridge.dao.IUserDAO;
import com.web.bridge.domain.User;
import com.web.bridge.service.IUserService;
@Service
@Cacheable(value="user")
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService {

	private IUserDAO userDao;
	@Autowired
	public void setUserDao(IUserDAO userDao){
		this.userDao=userDao;
	}
	
	@Override
	public User Login(String username, String password) throws ServiceException {
		// TODO Auto-generated method stub
		User user=userDao.findByName(username);
		if (user!=null&&user.getPassword().equals(password))
			return user;
		return null;
	}

	@Override
	public User get(String username) throws ServiceException {
		// TODO Auto-generated method stub
		User user=userDao.findByName(username);
		return user;
	}

	@Override
	public List<User> search(String username) throws ServiceException {
		// TODO Auto-generated method stub
		List<User> list=userDao.findByNameLike(username);
		return list;
	}
	
	public User register(User user){
		User u=userDao.findByName(user.getUsername());
		if (u!=null)
			return null;
		userDao.save(user);
		return user;
		
	}

}
